 /**
 * Description: 用户角色vo
 * Copyright:Copyright 2018 nfky.com. All rights reserved
 * @author:xk
 * @since:0.0.1
 * Create at:2018-01-10 下午 19:40:19
 *  
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2018-01-10   xk       0.0.1     Initial
 */
package com.metro.activation.sys.beans.vo;

import com.metro.utils.StringUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.metro.activation.sys.beans.entity.SysUserRoleEntity;

import java.util.ArrayList;
import java.util.List;

 /**
 * 用户角色vo<br>
 *
 * @author xk
 * @since [0.0.1]
 * @version [0.0.1, 2018-01-10]
 */
@Data()
@EqualsAndHashCode(callSuper = false)
public class SysUserRole extends SysUserRoleEntity{
     private String userIds;
     private Long[] userIdArr;
     private String roleIds;
     private Long[] roleIdArr;
     //columns END
     public Long[] getUserIdArr() {
         return userIdArr;
     }

     public void setUserIdArr(Long[] userIdArr) {
         this.userIdArr = userIdArr;
     }

     public Long[] getRoleIdArr() {
         return roleIdArr;
     }

     public void setRoleIdArr(Long[] roleIdArr) {
         this.roleIdArr = roleIdArr;
     }

     public String getUserIds() {
         return userIds;
     }

     public void setUserIds(String userIds) {
         this.userIds = userIds;
         userIdArr = StringUtil.split2LongArray(userIds);
     }

     public String getRoleIds() {
         return roleIds;
     }

     public void setRoleIds(String roleIds) {
         this.roleIds = roleIds;
         roleIdArr = StringUtil.split2LongArray(roleIds);
     }

     /**
      * 构建用户角色对应关系列表
      * @return
      */
     public List<SysUserRole> buildUserRoles(){
         if(this.getUserIdArr() != null && this.getUserIdArr().length > 0
                 && this.getRoleIdArr() != null && this.getRoleIdArr().length > 0){
             List<SysUserRole> userRoles = new ArrayList<>();
             SysUserRole userRole = null;
             for (int i = 0; i < this.getUserIdArr().length; i++) {
                 for (int j = 0; j < this.getRoleIdArr().length; j++) {
                     userRole = new SysUserRole();
                     userRole.setUserId(this.getUserIdArr()[i]);
                     userRole.setRoleId(this.getRoleIdArr()[j]);

                     userRoles.add(userRole);
                 }
             }
             return userRoles;
         }
         return null;
     }

}
